package top.zlhy7.module.work.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import top.zlhy7.enums.OrderTypeEnum;
import top.zlhy7.module.work.entity.WordOrder;

import java.util.Optional;

/**
 * @author renyong
 * @date 2024/9/29 19:33
 * @description 工单
 */
@AutoMapper(target = WordOrder.class)
@NoArgsConstructor
@Data
public class WordOrderVo extends WordOrder {
    /**
     * 工单类型 字面值
     */
    private String orderTypeStr;
    //region 筛选条件，仅接受不返回
    /**
     * 创建开始时间
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String createStartTime;
    /**
     * 创建结束时间
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String createEndTime;
    //endregion
    /**
     * 构造方法
     * @param wordOrder 工单实体
     */
    public WordOrderVo(WordOrder wordOrder){
        BeanUtils.copyProperties(wordOrder,this);
    }

    @Override
    public void setOrderType(Integer orderType) {
        super.setOrderType(orderType);
        if(orderType == null){
            return;
        }
        // 枚举转字符串
        Optional.ofNullable(orderType)
                .map(OrderTypeEnum.orderTypeEnumMap::get)
                .map(OrderTypeEnum::getDescription)
                .ifPresent(this::setOrderTypeStr);
    }
}
